package de.tum.beilmeiner.im.client.bundle;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.IsSerializable;

import de.novanic.eventservice.client.event.Event;
import de.novanic.eventservice.client.event.RemoteEventService;
import de.novanic.eventservice.client.event.RemoteEventServiceFactory;
import de.novanic.eventservice.client.event.domain.Domain;
import de.novanic.eventservice.client.event.listener.RemoteEventListener;
import de.tum.beilmeiner.im.client.InstantChat;
import de.tum.beilmeiner.im.client.MessagingService;
import de.tum.beilmeiner.im.client.MessagingServiceAsync;
import de.tum.beilmeiner.im.client.controller.ChatRoomController;
import de.tum.beilmeiner.im.client.event.ContactListUpdateEvent;
import de.tum.beilmeiner.im.client.event.CreateChatRoomEvent;
import de.tum.beilmeiner.im.client.event.IncomingMessageEvent;
import de.tum.beilmeiner.im.client.view.ChatRoomWindow;
import de.tum.beilmeiner.im.shared.model.ChatRoom;
import de.tum.beilmeiner.im.shared.model.UUID;
import de.tum.beilmeiner.im.shared.model.User;

public class ChatRoomBundle implements RemoteEventListener, IsSerializable{

	private Domain CHATROOM_UUID = null;
	private ChatRoom chatRoom = null;
	private ChatRoomWindow chatRoomWindow = null;
	private ChatRoomController chatRoomController = null;
	private final RemoteEventServiceFactory theEventServiceFactory = RemoteEventServiceFactory.getInstance();
	private final RemoteEventService theEventService = theEventServiceFactory.getRemoteEventService();
	
	public ChatRoomBundle(ChatRoom chatRoom, User creator)
	{
	this.CHATROOM_UUID = chatRoom.getUUID();
	this.chatRoom = chatRoom;
	chatRoomWindow = new ChatRoomWindow(chatRoom);
	chatRoomController = new ChatRoomController(chatRoomWindow);
	
	theEventService.addListener(chatRoom.getUUID(), this);
	
	}
	
	public ChatRoomBundle(){}

	public Domain getCHATROOM_UUID() {
		return CHATROOM_UUID;
	}

	public void setCHATROOM_UUID(Domain cHATROOM_UUID) {
		CHATROOM_UUID = cHATROOM_UUID;
	}

	public ChatRoom getChatRoom() {
		return chatRoom;
	}

	public void setChatRoom(ChatRoom chatRoom) {
		this.chatRoom = chatRoom;
	}

	public ChatRoomWindow getChatRoomWindow() {
		return chatRoomWindow;
	}

	public void setChatRoomWindow(ChatRoomWindow chatRoomWindow) {
		this.chatRoomWindow = chatRoomWindow;
	}

	public ChatRoomController getChatRoomController() {
		return chatRoomController;
	}

	public void setChatRoomController(ChatRoomController chatRoomController) {
		this.chatRoomController = chatRoomController;
	}

	@Override
	public void apply(Event anEvent) {
		if (anEvent instanceof CreateChatRoomEvent)
			onMyEvent((CreateChatRoomEvent) anEvent);
		
	}

	private void onMyEvent(CreateChatRoomEvent anEvent) {
		//chatRoomWindow.getParent().
		
	}
	
	
	
}
